#ifndef NEONWIDGET_HPP
#define NEONWIDGET_HPP

#include <QTimer>

#include "Global.hpp"
#include "Gl.hpp"
#include "Timer.hpp"

#include <QGLWidget>

namespace Neon
{
class NEON_DLL NeonWidget : public QGLWidget
{
	Q_OBJECT
public:
	/*!
	Creates a new Neon Widget.
	*\param title Title of the application.
	*\param interval Interval of the Scene being called.
	*\param parent QObject parent.
	*/
	NeonWidget(const QString &title, nint32 interval = 0, QWidget *parent = 0);

	virtual ~NeonWidget(){}

	/*!
	Gets the average frames per second.
	*\return Average frames per second.
	*/
	nulong averageFPS() const;

	/*!
	Gets the highest frame per second the application achieved.
	*\return Highest frame per second achieved.
	*/
	nulong bestFPS() const;

	/*!
	Gets the current frame per second for the current scene that rendered.
	*\return Current frame per second that rendered.
	*/
	nulong currentFPS() const;

	/*!
	Sets the current frame per second interval for vsync.
	*\param on true for v-sync; false for off.
	*/
	void swapInterval(bool on);

	/*!
	Gets the worst frame per second the application got.
	*\return Worst frame per second achieved.
	*/
	nulong worstFPS() const;
protected:
	virtual void initialise() = 0;

	virtual void keyPressEvent(QKeyEvent *e) = 0;

	virtual void mouseMoveEvent(QMouseEvent *e) = 0;

	virtual void mousePressEvent(QMouseEvent *e) = 0;

	virtual void resize(nuint32 width, nuint32 height) = 0;

	virtual void scene(nulong elapsedTime) = 0;

	virtual void timeOut();
protected slots:
	virtual void timedOut();
private:
	/*!
	Frames Per Second.
	*/
	struct FPS
	{
		/*!
		Average FPS.
		*/
		nulong avgFPS;

		/*!
		Current FPS.
		*/
		nulong curFPS;

		/*!
		FPS.
		*/
		nulong fps;

		/*!
		Minimum FPS
		*/
		nulong minFPS;

		/*!
		Maximum FPS.
		*/
		nulong maxFPS;
	}; // End of class FPS.

	void initializeGL();
	void paintGL();
	void resizeGL(int w, int h);
	QTimer *m_sceneTimer;
	Timer m_fpsTimer;
	FPS m_fps;
	nulong m_currentTime;
	nulong m_lastTime;
}; // End of class NeonWidget.

} // End of namespace Neon.

#endif // NEONWIDGET_HPP
